package com.hnkywl.sts.service.report;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.report.WlycwkcDao;
import com.hnkywl.sts.dao.report.ZcfzbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-6-14
 * Time: 下午4:50
 * To change this template use File | Settings | File Templates.
 */
@Service
public class ZcfzbService {
    private ZcfzbDao zcfzbDao;

    /**
     * 财务收发存报表
     *
     * @return
     */
    public String zcfzbList(Long gsId, Date startDate,Date endDate,Integer pageNo, Integer pageSize) {
        Map<String, List> result = zcfzbDao.zcfzbList(gsId, startDate,endDate,pageNo,pageSize);
        List<Map> rows = (List<Map>)result.get("rows");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String json = "{\"rows\":" + rowsJson + "}";
        return json;
    }

    public String findzcfzbmxList(Long type,Long gsId, Date dateStart, Date dateEnd, int pageNo, int pageSize) {
        Calendar c = Calendar.getInstance();
        c.setTime(dateEnd);
        c.set(Calendar.HOUR, 59);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 23);
        dateEnd = c.getTime();
        c.setTime(dateStart);
        c.set(Calendar.HOUR, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        Map result = zcfzbDao.findzcfzbmxList(type,gsId, c.getTime(), dateEnd, pageNo, pageSize);
        return "{\"total\":" + result.get("total") + ",\"rows\":" +
                new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(result.get("rows")) + ",\"footer\":" + new Gson().toJson(result.get("footer")) + "}";
    }

    public String cbjz(Long gsId, Date startDate,Date endDate) {
        return zcfzbDao.cbjz(gsId, startDate,endDate);
    }

    public Boolean checkZzcfzbJz(Date jzrq,Long gsId){
        return this.zcfzbDao.checkZzcfzbJz(jzrq,gsId);
    }

    @Autowired
    public void setZcfzbDao(ZcfzbDao zcfzbDao) {
        this.zcfzbDao = zcfzbDao;
    }
}
